home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue37 / DynArr / Array3U.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-07-03  |  1.7 KB  |  82 lines

  1. unit Array3U;
  2.  
  3. interface
  4.  
  5. uses
  6.   WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Grids, StdCtrls;
  8.  
  9. type
  10.   TArray3MainForm = class(TForm)
  11.     ListBox1: TListBox;
  12.     btnResizeArray: TButton;
  13.     btnFillArray: TButton;
  14.     procedure FormCreate(Sender: TObject);
  15.     procedure FormDestroy(Sender: TObject);
  16.     procedure btnResizeArrayClick(Sender: TObject);
  17.     procedure btnFillArrayClick(Sender: TObject);
  18.   private
  19.     MyArray: TList;
  20.     procedure DisplayArray;
  21.   end;
  22.  
  23. var
  24.   Array3MainForm: TArray3MainForm;
  25.  
  26. implementation
  27.  
  28. {$R *.DFM}
  29.  
  30. procedure TArray3MainForm.FormCreate(Sender: TObject);
  31. begin
  32.   MyArray := TList.Create;
  33.   MyArray.Count := StrToInt(InputBox(
  34.       'Enter your array dimensions',
  35.       'Number of elements:', '10'));
  36.   btnFillArray.Click; { Pretend to push the array filling button }
  37.   DisplayArray
  38. end;
  39.  
  40. procedure TArray3MainForm.FormDestroy(Sender: TObject);
  41. begin
  42.   MyArray.Free;
  43.   MyArray := nil
  44. end;
  45.  
  46. procedure TArray3MainForm.btnResizeArrayClick(Sender: TObject);
  47. begin
  48.   MyArray.Count := StrToInt(InputBox(
  49.     'Enter your new array dimensions',
  50.     'Number of elements:', '20'));
  51.   DisplayArray
  52. end;
  53.  
  54. procedure TArray3MainForm.btnFillArrayClick(Sender: TObject);
  55. var
  56.   Loop: Integer;
  57. begin
  58.   for Loop := 0 to Pred(MyArray.Count) do
  59.     MyArray[Loop] := Pointer(Loop);
  60.   DisplayArray
  61. end;
  62.  
  63. procedure TArray3MainForm.DisplayArray;
  64. var
  65.   Loop: Integer;
  66. begin
  67.   with ListBox1, Items do
  68.   begin
  69.     BeginUpdate;
  70.     try
  71.       Clear;
  72.       for Loop := 0 to Pred(MyArray.Count) do
  73.         Add(IntToStr(Integer(MyArray[Loop])));
  74.       ItemIndex := Pred(MyArray.Count)
  75.     finally
  76.       EndUpdate
  77.     end
  78.   end
  79. end;
  80.  
  81. end.
  82.